# 编译器
CC = gcc

# linux上编译出的可执行程序
targetlinux = queue

# windows 上编译出的可执行文件
targetwindows = queue.exe

# Linux 上编译出的答案
answerlinux = answer

# windows 上编译出的答案
answerwindows = answer.exe

answer = answer
# 解题用到的 .c 文件
targetcfile = main.c list.c queue.c
# 答案用到的 .c 文件
answercfile = main.c list.c answer.c

#linu
linuxtargetcobj = main.o list.o queue.o 
windowstargetobj = main.obj list.obj queue.obj

linuxanswertargetcobj := ${answer}main.o ${answer}list.o ${answer}answer.o 
windowsanswertargetobj := ${answer}main.obj ${answer}list.obj ${answer}answer.obj

.PHONY:
windows: $(targetwindows)
	$(targetwindows)
$(targetwindows): $(windowstargetobj)
	$(CC) $(windowstargetobj) -o $(targetwindows) -g
$(windowstargetobj):$(targetcfile)
	for tmp in $(targetcfile); do \
		echo $(CC) -c $$tmp -o $${tmp%%.*}.obj -g; \
		$(CC) -c $$tmp -o $${tmp%%.*}.obj -g;\
	done;


linux: $(targetlinux)
	./$(targetlinux)
$(targetlinux): $(linuxtargetcobj)
	$(CC) $(linuxtargetcobj) -o $(targetlinux) -g
$(linuxtargetcobj):$(targetcfile)
	for tmp in $(targetcfile); do \
		echo $(CC) -c $$tmp -o $${tmp%%.*}.o -g; \
		$(CC) -c $$tmp -o $${tmp%%.*}.o -g;\
	done;


windowsanswer: $(answerwindows)
	$(answerwindows)
$(answerwindows): $(windowsanswertargetobj)
	$(CC) $(windowsanswertargetobj) -o $(answerwindows) -g
$(windowsanswertargetobj):$(answercfile)
	for tmp in $(answercfile); do \
		echo $(CC) -c $$tmp -o ${answer}$${tmp%%.*}.obj -g; \
		$(CC) -c $$tmp -o ${answer}$${tmp%%.*}.obj -g;\
	done;


linuxanswer: $(answerlinux)
	./$(answerlinux)
$(answerlinux): $(linuxanswertargetcobj)
	$(CC) $(linuxanswertargetcobj) -o $(answerlinux) -g
$(linuxanswertargetcobj):$(answercfile)
	for tmp in $(answercfile); do \
		echo $(CC) -c $$tmp -o ${answer}$${tmp%%.*}.o -g; \
		$(CC) -c $$tmp -o ${answer}$${tmp%%.*}.o -g;\
	done;


cleanwindows:
	cmd /C del ${windowstargetobj}

cleanwindowsanswer:
	cmd /C del ${windowsanswertargetobj}

cleanlinux:
	rm ${linuxtargetcobj}

cleanlinuxanswer:
	rm ${linuxanswertargetcobj}